{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "super-maple",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/find-the-town-judge\n",
    "\n",
    "\n",
    "Runtime: 720 ms, faster than 87.04% of Python3 online submissions for Find the Town Judge.\n",
    "Memory Usage: 19.1 MB, less than 24.31% of Python3 online submissions for Find the Town Judge.\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def findJudge(self, N: int, trust: List[List[int]]) -> int:\n",
    "        #6:53\n",
    "        if len(trust) == 0 and N==1:\n",
    "            return 1\n",
    "        all_people = set([i for i in range(1, N+1)])\n",
    "        not_judge = set([l[0] for l in trust])\n",
    "        trusted = set([l[1] for l in trust])\n",
    "        #print(all_people)\n",
    "        #print(not_judge)\n",
    "        #print(trusted)\n",
    "        results = trusted & (all_people - not_judge)\n",
    "        if len(results) == 1:\n",
    "            possible = results.pop()\n",
    "            makesure = set([l[0] for l in trust if l[1] == possible])\n",
    "            if (makesure == not_judge):\n",
    "                return possible\n",
    "            else:\n",
    "                return -1\n",
    "        else:\n",
    "            return -1\n",
    "        #7:19\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adult-table",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
